﻿<?php
require_once ("db.php");

call_user_func($_POST['func']);


function getCards()
{
	$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

	// hämtar namn och id på bilderna beroende på vilket card man klickar på.
	$query = "SELECT image.id, image.name, latest_game.id as game_id
			  FROM image, card, (select id from game order by id desc limit 1) as latest_game
			  WHERE card.id
			  AND card.game_id=latest_game.id
			  AND image.id=card.image_id";
			
	$result = mysqli_query($dbc, $query);

		while($row = mysqli_fetch_assoc($result)) {
			$cards[] = $row;		
		}

	// Dubblar antal bilder genom att slå ihop arrays
	$cards = array_merge($cards, $cards);

	//shuffle cards
	shuffle($cards);

	for ( $i=0; $i<sizeof($cards); $i++ ) {
		echo "<span class='img_card'>";
		echo "<img id='back' src='images/memorybehind.jpg'>";
		echo "<img id='front' class='bricks' src='{$cards[$i]['name']}'>";
		echo "</span>";
	};
}
?>